package kernel.process;

import java.util.ArrayList;

import kernel.ProcessMemory;
import kernel.exception.OSException;

/**
 * Class responsible for deleting finished processes from process memory.
 * @author Petr Hajek
 *
 */
public class ProcessDestructor extends AbstractProcess {

	public ProcessDestructor(String name, ArrayList<String> params, String input, String output, boolean append, long pid) {
		super(name, params, input, output, append, pid, "root", 0);
		
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String doJob(String input) throws OSException {
		while(!shouldEnd) {
			try {
				long dispID = ProcessMemory.takeFromOldPQ();
				ProcessMemory.deleteProcess(dispID);
			} catch (InterruptedException e) {
				ProcessMemory.deleteProcess(0);
				return null;
			}
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void kill() throws OSException {
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean needParams() {
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String continueJob() throws OSException {
		shouldEnd = true;
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String finalizeJob() throws OSException {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String man(String command) {
		return "";
	}
}
